
package cn.edu.scau.cmi.hombio.service;

import cn.edu.scau.cmi.hombio.domain.MedicineStorage;
import cn.edu.scau.cmi.hombio.domain.MedicineSupplier;
import cn.edu.scau.cmi.hombio.domain.Supplier;

import java.util.List;
import java.util.Set;

import org.junit.Test;

import org.junit.runner.RunWith;

import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.beans.factory.support.DefaultListableBeanFactory;

import org.springframework.context.ApplicationContext;

import org.springframework.mock.web.MockHttpServletRequest;

import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.TestExecutionListeners;

import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import org.springframework.test.context.support.DependencyInjectionTestExecutionListener;
import org.springframework.test.context.support.DirtiesContextTestExecutionListener;

import org.springframework.test.context.transaction.TransactionalTestExecutionListener;

import org.springframework.transaction.annotation.Transactional;

import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.RequestScope;
import org.springframework.web.context.request.ServletRequestAttributes;
import org.springframework.web.context.request.SessionScope;

/**
 * Class to run the service as a JUnit test. Each operation in the service is a separate test.
 *
 */

@RunWith(SpringJUnit4ClassRunner.class)
@TestExecutionListeners({
		DependencyInjectionTestExecutionListener.class,
		DirtiesContextTestExecutionListener.class,
		TransactionalTestExecutionListener.class })
@ContextConfiguration(locations = {
		"file:./resources/pigRs-security-context.xml",
		"file:./resources/pigRs-service-context.xml",
		"file:./resources/pigRs-dao-context.xml",
		"file:./resources/pigRs-web-context.xml" })
@Transactional
public class SupplierServiceTest {

	/**
	 * The Spring application context.
	 *
	 */
	@SuppressWarnings("unused")
	private ApplicationContext context;

	/**
	 * The service being tested, injected by Spring.
	 *
	 */
	@Autowired
	protected SupplierService service;

	/**
	 * Instantiates a new SupplierServiceTest.
	 *
	 */
	public SupplierServiceTest() {
		setupRequestContext();
	}

	/**
	 * Operation Unit Test
	* Save an existing MedicineSupplier entity
	* 
	 */
	@Test
	public void saveSupplierMedicineSuppliers() {
		// TODO: JUnit - Populate test inputs for operation: saveSupplierMedicineSuppliers 
		Integer id = 0;
		MedicineSupplier related_medicinesuppliers = new cn.edu.scau.cmi.hombio.domain.MedicineSupplier();
		Supplier response = null;
		response = service.saveSupplierMedicineSuppliers(id, related_medicinesuppliers);
		// TODO: JUnit - Add assertions to test outputs of operation: saveSupplierMedicineSuppliers
	}

	/**
	 * Operation Unit Test
	 */
	@Test
	public void findSupplierByPrimaryKey() {
		// TODO: JUnit - Populate test inputs for operation: findSupplierByPrimaryKey 
		Integer id_1 = 0;
		Supplier response = null;
		response = service.findSupplierByPrimaryKey(id_1);
		// TODO: JUnit - Add assertions to test outputs of operation: findSupplierByPrimaryKey
	}

	/**
	 * Operation Unit Test
	* Return a count of all Supplier entity
	* 
	 */
	@Test
	public void countSuppliers() {
		Integer response = null;
		response = service.countSuppliers();
		// TODO: JUnit - Add assertions to test outputs of operation: countSuppliers
	}

	/**
	 * Operation Unit Test
	* Delete an existing MedicineSupplier entity
	* 
	 */
	@Test
	public void deleteSupplierMedicineSuppliers() {
		// TODO: JUnit - Populate test inputs for operation: deleteSupplierMedicineSuppliers 
		Integer supplier_id = 0;
		Integer related_medicinesuppliers_id = 0;
		Supplier response = null;
		response = service.deleteSupplierMedicineSuppliers(supplier_id, related_medicinesuppliers_id);
		// TODO: JUnit - Add assertions to test outputs of operation: deleteSupplierMedicineSuppliers
	}

	/**
	 * Operation Unit Test
	* Save an existing Supplier entity
	* 
	 */
	@Test
	public void saveSupplier() {
		// TODO: JUnit - Populate test inputs for operation: saveSupplier 
		Supplier supplier = new cn.edu.scau.cmi.hombio.domain.Supplier();
		service.saveSupplier(supplier);
	}

	/**
	 * Operation Unit Test
	* Delete an existing MedicineStorage entity
	* 
	 */
	@Test
	public void deleteSupplierMedicineStorages() {
		// TODO: JUnit - Populate test inputs for operation: deleteSupplierMedicineStorages 
		Integer supplier_id_1 = 0;
		Integer related_medicinestorages_id = 0;
		Supplier response = null;
		response = service.deleteSupplierMedicineStorages(supplier_id_1, related_medicinestorages_id);
		// TODO: JUnit - Add assertions to test outputs of operation: deleteSupplierMedicineStorages
	}

	/**
	 * Operation Unit Test
	* Delete an existing Supplier entity
	* 
	 */
	@Test
	public void deleteSupplier() {
		// TODO: JUnit - Populate test inputs for operation: deleteSupplier 
		Supplier supplier_1 = new cn.edu.scau.cmi.hombio.domain.Supplier();
		service.deleteSupplier(supplier_1);
	}

	/**
	 * Operation Unit Test
	* Load an existing Supplier entity
	* 
	 */
	@Test
	public void loadSuppliers() {
		Set<Supplier> response = null;
		response = service.loadSuppliers();
		// TODO: JUnit - Add assertions to test outputs of operation: loadSuppliers
	}

	/**
	 * Operation Unit Test
	* Return all Supplier entity
	* 
	 */
	@Test
	public void findAllSuppliers() {
		// TODO: JUnit - Populate test inputs for operation: findAllSuppliers 
		Integer startResult = 0;
		Integer maxRows = 0;
		List<Supplier> response = null;
		response = service.findAllSuppliers(startResult, maxRows);
		// TODO: JUnit - Add assertions to test outputs of operation: findAllSuppliers
	}

	/**
	 * Operation Unit Test
	* Save an existing MedicineStorage entity
	* 
	 */
	@Test
	public void saveSupplierMedicineStorages() {
		// TODO: JUnit - Populate test inputs for operation: saveSupplierMedicineStorages 
		Integer id_2 = 0;
		MedicineStorage related_medicinestorages = new cn.edu.scau.cmi.hombio.domain.MedicineStorage();
		Supplier response = null;
		response = service.saveSupplierMedicineStorages(id_2, related_medicinestorages);
		// TODO: JUnit - Add assertions to test outputs of operation: saveSupplierMedicineStorages
	}

	/**
	 * Autowired to set the Spring application context.
	 *
	 */
	@Autowired
	public void setContext(ApplicationContext context) {
		this.context = context;
		((DefaultListableBeanFactory) context.getAutowireCapableBeanFactory()).registerScope("session", new SessionScope());
		((DefaultListableBeanFactory) context.getAutowireCapableBeanFactory()).registerScope("request", new RequestScope());
	}

	/**
	 * Sets Up the Request context
	 *
	 */
	private void setupRequestContext() {
		MockHttpServletRequest request = new MockHttpServletRequest();
		ServletRequestAttributes attributes = new ServletRequestAttributes(request);
		RequestContextHolder.setRequestAttributes(attributes);
	}
}
